@layout('layouts.clearly')

@section('content')
@id('news.post')


<?php

if (!isset($article)) {
    $article = array();
    $fields = array('title', 'thumbnail', 'brief', 'body');
    foreach ($fields as $field) {
        $article[$field] = Input::old($field, '');
    }

    $article = (object) $article;
}

isset ($action) || $action = asset('news/post')



?>

<div class="page-head">
    <h1>Đăng tin</h1>
</div>

<div class="container page-outer">
    <div class="w640" id="post-form-outer">
        @if ($errors->has())
        <div class="form-errors">
            <ul>
                {{ $errors->first('title', '<li>:message</li>') }}
                {{ $errors->first('title', '<li>:message</li>') }}
                {{ $errors->first('body', '<li>:message</li>') }}
            </ul>
        </div>
        @endif

        <form action="{{ $action }}" method="POST" id="news-post-form" enctype="multipart/form-data" class="w640">
            <fieldset>
                <legend>Đăng bài viết mới</legend>
                <div class="control-group required">
                    <label for="title">Tiêu đề</label>
                    <div class="controls">
                        <input type="text" name="title" id="title" class="w-full" value="{{ $article->title }}" />
                    </div>
                </div>


                <div class="control-group">
                    <label for="thumbnail-link">
                        Ảnh đại diện (<em>Điền đường dẫn (URL) của ảnh vào bên dưới</em>
                        <a class="file-selector spec recommend" href="#thumbnail" id="thumb-selector">hoặc chọn ảnh để tải lên</a>)
                    </label>
                    <div class="controls">
                        <input type="file" name="thumbnail" id="thumbnail" class="hidden" />
                        <input type="text" name="thumblink" id="thumbnail-link" class="w-full" value="{{ $article->thumbnail }}">
                    </div>
                </div>

                <div class="control-group required">
                    <label for="brief">Giới thiệu (mô tả ngắn gọn bài viết)</label>
                    <div class="controls">
                        <textarea name="brief" id="brief" rows="3" class="w-full">{{ $article->brief }}</textarea>
                    </div>
                </div>

                <div class="control-group required">
                    <label for="body">Nội dung bài viết</label>
                    <div class="controls wmd-panel clear-fix">
                        <div id="wmd-button-bar"></div>
                        <textarea class="wmd-input w-full" name="body" id="body" cols="30" rows="10">{{ $article->body }}</textarea>
                        <a href="#" class="toggle spec" data-func="toggle" id="preview-link"
                           data-toggle-target="#news-preview"
                           data-toggle-prevent="true">
                            Bật/tắt xem trước
                        </a>
                    </div>
                    <div class="news-view" id="news-preview">
                        <div class="news-content">
                            <div class="wmd-panel content" id="wmd-preview"></div>
                        </div>
                    </div>
                </div>

                <div class="control-group ta-right">
                    {{ Form::token() }}


                    <div class="controls">
                        <button type="submit" class="btn btn-primary btn-large">Đăng bài</button>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>
</div>

@endsection